//===============================================================================
// Microsoft patterns & practices Enterprise Library Contribution
// Query Application Block
//===============================================================================

using System;
using EntLibContrib.Query.Properties;

namespace EntLibContrib.Query.Parameters
{
	/// <summary>
	/// Base type to hold the name and value elements of a single name and value query parameter
	/// </summary>
	public abstract class Parameter : IParameter
	{
		#region Fields
		private string name;
		private object dataValue;
		#endregion

		#region Properties
		/// <summary>
		/// Gets or sets the name of the parameter.
		/// </summary>
		/// <value>The name of the parameter.</value>
		/// <remarks>Exclude parameter name tokens for generic queries e.g. for SQL parameter formats
		/// like @Name the @ symbol prefix can be excluded</remarks>
		public string Name
		{
			get { return name; }
			set { name = value; }
		}

		/// <summary>
		/// Gets or sets the parameter value.
		/// </summary>
		/// <value>The parameter value.</value>
		public object Value
		{
			get { return dataValue; }
			set { dataValue = value; }
		}
		#endregion

		#region Construction
		/// <summary>
		/// Initializes a new default instance of the <see cref="Parameter"/> class.
		/// </summary>
		/// <param name="name">The parameter name.</param>
		protected Parameter(string name)
		{
			ValidateAndStoreParameters(name);
		}
		#endregion

		#region Private Methods
		/// <summary>
		/// Validates and stores the parameters.
		/// </summary>
		/// <param name="parameterName">Name of the parameter.</param>
		private void ValidateAndStoreParameters(string parameterName)
		{
			// check for a null or empty name
			if (string.IsNullOrEmpty(parameterName))
				throw new ArgumentNullException("parameterName", InternalResources.ExceptionParameterNameNullOrEmpty);
			// store the name
			this.Name = parameterName;
		}
		#endregion
	}
}
